package servlet;
/*
 * 可以选择保存路径功能
 */
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Scanner;

import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.XMLWriter;

public class ConfigUtil {
	public static void main(String[] args) throws IOException {
		createXmlConfig();
	}
	
	private void createXmlConfigSwing() {
		
	}
	
	private static void createXmlConfig() throws IOException {
		Scanner in = new Scanner(System.in);
		System.out.println("url:");
		String url = in.nextLine();
		System.out.println("driver:");
		String driver = in.nextLine();
		System.out.println("username:");
		String username = in.nextLine();
		System.out.println("pwd:");
		String pwd = in.nextLine();
		System.out.println("xml file path:");
		String path = in.nextLine();
		
		Document config = DocumentHelper.createDocument();
		Element jdbc =config.addElement("jdbc");
		jdbc.addElement("url").setText(url);
		jdbc.addElement("driver").setText(driver);
		jdbc.addElement("username").setText(username);
		jdbc.addElement("pwd").setText(pwd);
		
		OutputFormat f = OutputFormat.createPrettyPrint();
		XMLWriter writer = new XMLWriter(new FileOutputStream(path),f);
		writer.write(config);
		System.out.println("saved successfully");
	}
}
